<template>
    <!-- 推荐商品 -->
    <div class="main-container">
        <!-- <navbar title="商品列表"></navbar> -->
        <div class="goodslistContainer">
            <div class="goods-list">

                <div class="goods-item" v-for="(item,i) in list" :key="i" @click="gotoDetail(item.id)">
                    <div class="imgbox">
                        <img :src="item.imgsrc" alt="">
                    </div>
                    <h1>{{item.title}}</h1>
                    <div class="info">
                        <div class="price">
                            <span class="now">
                                <span class="symbol">￥</span>{{item.price | priceFormat}}</span>
                            <span class="old">
                                <span class="symbol">￥</span>{{item.oldprice | priceFormat}}</span>
                        </div>
                        <div class="tip">
                            <span>热卖中</span>
                            <span>剩余{{item.yu}}件</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="txtip">
            <span>已经到底了</span>
        </div>
    </div>

</template>

<script>
    import VueRouter from 'vue-router'
    import NavBar from '../common/navbar.vue'

    // 下拉/上拉刷新
    // import {
    //     Loadmore
    // } from 'mint-ui';


    export default {
        data() {
            return {
                //默认数据
                list: [],
                //搜索关键词
                keyword: ''
            }
        },
        created() {
            this.getgoodslist();
        },
        methods: {

            //获得商品列表
            getgoodslist() {
                this.$http.get("api/getgoodslist").then(
                    res => {
                        console.log("获取商品列表成功");
                        console.log(res);
                        if (res.body.status == 0) {
                            this.list = res.body.message;
                        } else {
                            console.log("no");
                        }
                    },
                    res => {
                        console.log("error callback");
                        console.log(res);
                    }
                );
            },
            gotoDetail(id) {

                //router 编程式导航

                // 注意：route 是路由参数对象，router 是路由导航对象

                // 普通方式： this.$router.push('/home/shop/goods/'+id)
                // 传递对象：this.$router.push({ path :'/home/shop/goods/'+id })
                // 传递路由规则的名称 
                this.$router.push({
                    name: 'goods',
                    params: {
                        id: id
                    }
                })

                //this.$router.go(-1);
                //this.$router.go(1);
                //this.$router.back();

                console.log(this.$router);
            }

        },
        components: {
            navbar: NavBar
        }
    }
</script>
<style lang="scss">
    .mint-search {
        height: auto;
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
    }

    input[type=search].mint-searchbar-core {
        padding: 0;
        background-color: transparent;
        margin: 0;
        font-size: 14px;
    }
</style>
<style lang="scss" scoped>
    .goods-list {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        padding: 10px;

        .goods-item {

            width: 49%;
            border: 1px solid #ccc; // margin-right: 10px;
            margin-bottom: 10px;
            box-shadow: 0 0 6px #ccc;
            border-radius: 3px;
            min-height: 293px;

            display: flex;
            flex-direction: column;
            justify-content: space-between;

            h1 {
                font-size: 14px;
                padding: 0 10px;
                line-height: 1.3;
                margin-bottom: 10px;
                text-overflow: ellipsis;
                overflow: hidden;
                height: 33px;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;

            }
            .imgbox {
                width: 100%; // height: 200px;
                overflow: hidden;
                img {
                    width: 100%;
                    height: auto;
                }
            }

            .info {
                padding: 10px 10px 5px;
                background-color: #eee;

                .price {
                    display: flex;
                    .now {
                        font-weight: bold;
                        color: #e4393c;
                        font-size: 18px;
                        padding-right: 5px;

                        .symbol {
                            font-size: 12px;
                        }
                    }
                    .old {
                        text-decoration: line-through;
                        color: #333;
                        font-size: 12px;
                    }
                }
                .tip {
                    font-size: 14px;
                    display: flex;
                    justify-content: space-between;
                    padding-top: 3px;
                }
            }
        }
    }

    .txtip {
        text-align: center;
        height: 30px;
        line-height: 0;
        margin-top: 45px;

        span {
            background: #fff;
            color: #999;
            padding: 0 15px;
        }
    }

    .txtip:after {
        content: '';
        width: 100%;
        height: 1px;
        display: block;
        background: #ccc;
    }
</style>